<template>
  <div class="dashboard-container">
    <!-- 页面标题 -->
    <!-- <div class="dashboard-header">
      <h1>Dashboard</h1>
    </div> -->

    <!-- 统计卡片区域 -->
    <div class="dashboard-stats">
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="stat-card">
            <div class="stat-header">
              <span class="stat-label">今日注册用户</span>
            </div>
            <div class="stat-content">
              <div class="stat-value-wrapper">
                <div class="stat-value">{{ dashboardStats.userCount }}</div>
              </div>
              <div class="stat-icon users-icon">
                <el-icon><User /></el-icon>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card">
            <div class="stat-header">
              <span class="stat-label">今日活跃用户</span>
            </div>
            <div class="stat-content">
              <div class="stat-value-wrapper">
                <div class="stat-value">{{ dashboardStats.onlineUsers }}</div>
              </div>
              <div class="stat-icon online-icon">
                <el-icon><Connection /></el-icon>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card">
            <div class="stat-header">
              <span class="stat-label">今日交易量</span>
            </div>
            <div class="stat-content">
              <div class="stat-value-wrapper">
                <div class="stat-value">{{ dashboardStats.tradeCount }}</div>
              </div>
              <div class="stat-icon trade-icon">
                <el-icon><Goods /></el-icon>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card">
            <div class="stat-header">
              <span class="stat-label">今日交易额</span>
            </div>
            <div class="stat-content">
              <div class="stat-value-wrapper">
                <div class="stat-value">{{ dashboardStats.tradeAmount }}</div>
              </div>
              <div class="stat-icon money-icon">
                <el-icon><Money /></el-icon>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    
    <!-- 图表区域 -->
    <div class="dashboard-charts">
      <!-- 每日数据走势图 -->
      <div class="chart-section">
        <div class="chart-header">
          <div class="chart-title">
            <h2>每日数据统计</h2>
          </div>
          <div class="chart-actions">
            <el-radio-group v-model="activeChartTab" @change="handleChartTabChange" size="small">
              <el-radio-button label="all">综合数据</el-radio-button>
              <el-radio-button label="users">注册用户</el-radio-button>
              <el-radio-button label="trades">交易数量</el-radio-button>
              <el-radio-button label="amount">交易金额</el-radio-button>
              <el-radio-button label="active">活跃用户</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <div class="chart-container" ref="dailyStatsChartRef" style="height: 320px;"></div>
      </div>
      
      <!-- 数据分析区域，使用两列布局 -->
      <el-row :gutter="20" style="margin-top: 20px;">
        <!-- 交易物品类型分布 - 宽度从 12 减小到 9 -->
        <el-col :span="9">
          <div class="chart-section" style="height: 400px;">
            <div class="chart-header">
              <div class="chart-title">
                <h2>交易物品类型分布</h2>
              </div>
              <div class="chart-actions">
                <el-radio-group v-model="itemTypeTimeRange" @change="handleItemTypeTimeRangeChange" size="small">
                  <el-radio-button label="all">综合数据</el-radio-button>
                  <el-radio-button label="today">今日</el-radio-button>
                  <el-radio-button label="week">本周</el-radio-button>
                  <el-radio-button label="month">本月</el-radio-button>
                </el-radio-group>
              </div>
            </div>
            <div class="chart-container" ref="itemTypePieRef" style="height: calc(100% - 60px);"></div>
          </div>
        </el-col>
        
        <!-- 交易榜单 - 宽度从 12 增加到 15 -->
        <el-col :span="15">
          <div class="chart-section" style="height: 400px;">
            <div class="chart-header">
              <div class="chart-title">
                <h2>交易榜单</h2>
              </div>
              <div class="chart-actions">
                <!-- 榜单类型切换 -->
                <el-radio-group v-model="rankType" @change="handleRankTypeChange" size="small" style="margin-right: 12px;">
                  <el-radio-button label="user">用户榜单</el-radio-button>
                  <el-radio-button label="product">商品榜单</el-radio-button>
                </el-radio-group>
                
                <!-- 时间范围选择 -->
                <el-radio-group v-model="tradeRankTimeRange" @change="handleTradeRankTimeRangeChange" size="small">
                  <el-radio-button label="all">综合数据</el-radio-button>
                  <el-radio-button label="today">今日</el-radio-button>
                  <el-radio-button label="week">本周</el-radio-button>
                  <el-radio-button label="month">本月</el-radio-button>
                </el-radio-group>
              </div>
            </div>
            <div class="rank-table-container" style="height: calc(100% - 60px);">
              <!-- 用户交易榜单 -->
              <el-table v-show="rankType === 'user'" :data="userTradeRankData" style="width: 100%; height: 100%" size="small" :stripe="true">
                <el-table-column prop="rank" label="排名" width="80" align="center">
                  <template #default="scope">
                    <div class="rank-tag" :class="{ 
                        'rank-1': scope.row.rank === 1, 
                        'rank-2': scope.row.rank === 2, 
                        'rank-3': scope.row.rank === 3 
                      }">
                      {{ scope.row.rank }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="userName" label="用户" min-width="180">
                  <template #default="scope">
                    <div class="user-cell">
                      <span class="user-avatar" :style="{ backgroundColor: scope.row.avatarColor }">
                        {{ scope.row.userName.charAt(0) }}
                      </span>
                      <span class="user-name">{{ scope.row.userName }}</span>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="tradeCount" label="交易数量" min-width="150" align="center" sortable />
                <el-table-column prop="tradeAmount" label="交易金额" min-width="150" align="center" sortable />
              </el-table>
              
              <!-- 商品交易榜单 -->
              <el-table v-show="rankType === 'product'" :data="productTradeRankData" style="width: 100%; height: 100%" size="small" :stripe="true">
                <el-table-column prop="rank" label="排名" width="80" align="center">
                  <template #default="scope">
                    <div class="rank-tag" :class="{ 
                        'rank-1': scope.row.rank === 1, 
                        'rank-2': scope.row.rank === 2, 
                        'rank-3': scope.row.rank === 3 
                      }">
                      {{ scope.row.rank }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="productName" label="商品" min-width="180">
                  <template #default="scope">
                    <div class="product-cell">
                      <span class="product-icon" :style="{ backgroundColor: scope.row.iconColor }">
                        <el-icon><Goods /></el-icon>
                      </span>
                      <span class="product-name">{{ scope.row.productName }}</span>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="category" label="分类" min-width="120" align="center" />
                <el-table-column prop="saleCount" label="销量" min-width="120" align="center" sortable />
                <el-table-column prop="saleAmount" label="销售额" min-width="120" align="center" sortable />
              </el-table>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue'
import { 
  User, Connection, Goods, Money, DataBoard, 
  ArrowUp, ArrowDown, Download, ShoppingBag
} from '@element-plus/icons-vue'

// 导入 echarts
import * as echarts from 'echarts/core'
import { LineChart, BarChart, PieChart } from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DataZoomComponent,
  LegendComponent
} from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'

// 注册必要的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DataZoomComponent,
  LegendComponent,
  LineChart,
  BarChart,
  PieChart,
  CanvasRenderer
])

// 控制面板相关数据
const dashboardStats = reactive({
  userCount: '8,526',
  onlineUsers: '253',
  tradeCount: '1,342',
  tradeAmount: '152,800'
})

// 活跃图表标签
const activeChartTab = ref('all')
const itemTypeTimeRange = ref('all')

// 图表相关引用
const dailyStatsChartRef = ref(null)
const itemTypePieRef = ref(null)

// 图表实例
let dailyStatsChart = null
let itemTypePie = null

// 榜单类型和时间范围
const rankType = ref('user')
const tradeRankTimeRange = ref('all')

// 用户交易榜单数据
const userTradeRankData = ref([
  { rank: 1, userName: '用户A', avatarColor: '#4facfe', tradeCount: 156, tradeAmount: '89,500' },
  { rank: 2, userName: '用户B', avatarColor: '#43e97b', tradeCount: 142, tradeAmount: '78,300' },
  { rank: 3, userName: '用户C', avatarColor: '#f78ca0', tradeCount: 125, tradeAmount: '65,200' },
  { rank: 4, userName: '用户D', avatarColor: '#a18cd1', tradeCount: 110, tradeAmount: '52,800' },
  { rank: 5, userName: '用户E', avatarColor: '#fbc2eb', tradeCount: 98, tradeAmount: '45,600' },
  { rank: 6, userName: '用户F', avatarColor: '#ffd86f', tradeCount: 86, tradeAmount: '38,200' },
  { rank: 7, userName: '用户G', avatarColor: '#84fab0', tradeCount: 75, tradeAmount: '32,100' },
  { rank: 8, userName: '用户H', avatarColor: '#8fd3f4', tradeCount: 64, tradeAmount: '28,500' }
])

// 商品交易榜单数据
const productTradeRankData = ref([
  { rank: 1, productName: '火焰喵', category: '宠物', iconColor: '#f5bf42', saleCount: 89, saleAmount: '53,400' },
  { rank: 2, productName: '高级精灵球', category: '精灵球', iconColor: '#4facfe', saleCount: 76, saleAmount: '45,600' },
  { rank: 3, productName: '闪光图鉴', category: '其他道具', iconColor: '#cd7f32', saleCount: 68, saleAmount: '40,800' },
  { rank: 4, productName: '草系喵', category: '宠物', iconColor: '#43e97b', saleCount: 62, saleAmount: '37,200' },
  { rank: 5, productName: '能量果实', category: '树果', iconColor: '#f78ca0', saleCount: 55, saleAmount: '33,000' },
  { rank: 6, productName: '特效恢复剂', category: '药剂', iconColor: '#a18cd1', saleCount: 49, saleAmount: '29,400' },
  { rank: 7, productName: '水系喵', category: '宠物', iconColor: '#8fd3f4', saleCount: 42, saleAmount: '25,200' },
  { rank: 8, productName: '进化石', category: '其他道具', iconColor: '#fbc2eb', saleCount: 37, saleAmount: '22,200' }
])

// 处理图表标签切换
const handleChartTabChange = (tab) => {
  initDailyStatsChart(tab)
}

// 添加时间范围变化的处理函数
const handleItemTypeTimeRangeChange = () => {
  initItemTypePie()
}

// 初始化所有图表
const initCharts = () => {
  initDailyStatsChart(activeChartTab.value)
  initItemTypePie()
}

// 初始化每日数据统计图表
const initDailyStatsChart = (tab = 'all') => {
  if (!dailyStatsChartRef.value) return
  
  // 销毁现有实例
  if (dailyStatsChart) {
    dailyStatsChart.dispose()
  }
  
  // 初始化图表
  dailyStatsChart = echarts.init(dailyStatsChartRef.value)
  
  // 准备模拟数据 - 过去30天的数据
  const dates = []
  const registeredUserData = []
  const tradeCountData = []
  const tradeAmountData = []
  const activeUserData = []
  
  const now = new Date()
  for (let i = 29; i >= 0; i--) {
    const date = new Date(now)
    date.setDate(date.getDate() - i)
    dates.push(`${date.getMonth() + 1}/${date.getDate()}`)
    
    // 生成随机数据，但保持一定的趋势
    const base = 30 - i // 时间越近，基础值越高
    const regUserCount = Math.floor(Math.random() * 10 + base * 0.5)
    const tradeCount = Math.floor(Math.random() * 40 + base * 1.5)
    const activeUserCount = Math.floor(Math.random() * 30 + base)
    const tradeAmount = Math.floor((tradeCount * 800 + Math.random() * 5000) / 100) * 100
    
    registeredUserData.push(regUserCount)
    tradeCountData.push(tradeCount)
    tradeAmountData.push(tradeAmount)
    activeUserData.push(activeUserCount)
  }
  
  // 根据选中的标签配置不同的图表
  let series = []
  let yAxis = []
  
  if (tab === 'all') {
    // 综合数据视图
    series = [
      {
        name: '今日注册用户',
        type: 'bar',
        data: registeredUserData,
        barWidth: 6,
        itemStyle: { color: '#4facfe' }
      },
      {
        name: '交易数量',
        type: 'bar',
        data: tradeCountData,
        barWidth: 6,
        itemStyle: { color: '#43e97b' }
      },
      {
        name: '今日活跃用户',
        type: 'line',
        smooth: true,
        data: activeUserData,
        itemStyle: { color: '#ee6666' },
        lineStyle: { width: 3 },
        symbol: 'circle',
        symbolSize: 8
      },
      {
        name: '交易金额',
        type: 'line',
        smooth: true,
        yAxisIndex: 1,
        data: tradeAmountData,
        itemStyle: { color: '#a18cd1' },
        lineStyle: { width: 3 },
        symbol: 'circle',
        symbolSize: 8
      }
    ]
    
    yAxis = [
      {
        type: 'value',
        name: '数量',
        position: 'left',
        axisLine: {
          show: true,
          lineStyle: { color: '#999' }
        }
      },
      {
        type: 'value',
        name: '金额',
        position: 'right',
        axisLine: {
          show: true,
          lineStyle: { color: '#999' }
        },
        axisLabel: {
          formatter: '{value}'
        }
      }
    ]
  } else if (tab === 'users') {
    // 注册用户视图
    series = [
      {
        name: '每日新增用户',
        type: 'bar',
        barWidth: 12,
        data: registeredUserData,
        itemStyle: {
          color: '#4facfe'
        },
        markLine: {
          data: [{ type: 'average', name: '平均值' }]
        }
      }
    ]
    
    yAxis = [
      {
        type: 'value',
        name: '用户数',
        axisLine: { show: true }
      }
    ]
  } else if (tab === 'trades') {
    // 交易数量视图
    series = [
      {
        name: '每日交易数量',
        type: 'bar',
        barWidth: 12,
        data: tradeCountData,
        itemStyle: {
          color: '#43e97b'
        },
        markLine: {
          data: [{ type: 'average', name: '平均值' }]
        }
      }
    ]
    
    yAxis = [
      {
        type: 'value',
        name: '交易数',
        axisLine: { show: true }
      }
    ]
  } else if (tab === 'amount') {
    // 交易金额视图
    series = [
      {
        name: '每日交易金额',
        type: 'line',
        smooth: true,
        data: tradeAmountData,
        itemStyle: { color: '#a18cd1' },
        lineStyle: {
          width: 4,
        },
        symbol: 'circle',
        symbolSize: 8,
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: 'rgba(161, 140, 209, 0.5)' },
            { offset: 1, color: 'rgba(161, 140, 209, 0.1)' }
          ])
        },
        markLine: {
          data: [{ type: 'average', name: '平均值' }]
        }
      }
    ]
    
    yAxis = [
      {
        type: 'value',
        name: '金额',
        axisLine: { show: true },
        axisLabel: {
          formatter: '{value}'
        }
      }
    ]
  } else if (tab === 'active') {
    // 活跃用户视图
    series = [
      {
        name: '每日活跃用户',
        type: 'line',
        smooth: true,
        data: activeUserData,
        itemStyle: { color: '#ee6666' },
        lineStyle: {
          width: 4,
        },
        symbol: 'circle',
        symbolSize: 8,
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: 'rgba(238, 102, 102, 0.5)' },
            { offset: 1, color: 'rgba(238, 102, 102, 0.1)' }
          ])
        },
        markLine: {
          data: [{ type: 'average', name: '平均值' }]
        }
      }
    ]
    
    yAxis = [
      {
        type: 'value',
        name: '用户数',
        axisLine: { show: true }
      }
    ]
  }
  
  // 配置图表选项
  const option = {
    backgroundColor: 'transparent',
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'line',
        lineStyle: {
          color: '#cccccc',
          width: 1
        }
      },
      backgroundColor: 'rgba(255, 255, 255, 0.9)',
      borderWidth: 1,
      borderColor: '#eeeeee',
      padding: [10, 12],
      textStyle: {
        color: '#333333',
        fontSize: 12
      },
      position: function (pos, params, el, elRect, size) {
        const obj = { top: 10 };
        obj.left = pos[0] < size.viewSize[0] / 4 * 3 ? pos[0] + 10 : pos[0] - size.contentSize[0] - 10;
        return obj;
      },
      extraCssText: 'box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); z-index: 100;'
    },
    legend: {
      data: series.map(item => item.name),
      textStyle: {
        fontSize: 12,
        color: '#666'
      },
      icon: 'circle',
      itemWidth: 8,
      itemHeight: 8,
      itemGap: 15,
      right: 'auto',
      top: 0,
      left: 'center',
      orient: 'horizontal',
      padding: [5, 10]
    },
    grid: {
      left: '30px',
      right: '40px',
      bottom: '40px',
      top: '50px',
      containLabel: true
    },
    dataZoom: [
      {
        type: 'inside',
        start: 0,
        end: 100
      },
      {
        type: 'slider',
        start: 0,
        end: 100,
        height: 15,
        bottom: 5,
        borderColor: 'transparent',
        backgroundColor: '#f5f5f5',
        fillerColor: 'rgba(80, 143, 255, 0.1)',
        handleStyle: {
          color: '#6e8ffb',
          borderColor: '#6e8ffb'
        },
        handleSize: '100%',
        textStyle: {
          fontSize: 10,
          color: '#999'
        },
        moveHandleStyle: {
          height: 10
        },
        moveHandleSize: 5
      }
    ],
    xAxis: [
      {
        type: 'category',
        data: dates,
        axisTick: {
          alignWithLabel: true,
          lineStyle: {
            color: '#eeeeee'
          }
        },
        axisLine: {
          lineStyle: {
            color: '#eeeeee'
          }
        },
        axisLabel: {
          fontSize: 10,
          color: '#999',
          margin: 12,
          formatter: function(value) {
            return value;
          }
        }
      }
    ],
    yAxis: yAxis.map(axis => {
      return {
        ...axis,
        axisLabel: {
          ...axis.axisLabel,
          fontSize: 10,
          color: '#999',
          padding: [0, 10, 0, 0],
          formatter: function(value) {
            if (axis.name === '金额' && value >= 10000) {
              return (value / 10000).toFixed(1) + 'w';
            }
            return value;
          }
        },
        splitLine: {
          lineStyle: {
            color: '#eeeeee'
          }
        }
      }
    }),
    series: series.map(serie => {
      if (serie.name === '交易金额' || serie.yAxisIndex === 1) {
        return {
          ...serie,
          label: {
            show: false
          },
          symbolSize: 6,
          markPoint: {
            symbol: 'circle',
            symbolSize: 5,
            data: [
              { type: 'max', name: '最大值', label: { show: false } },
              { type: 'min', name: '最小值', label: { show: false } }
            ]
          }
        };
      }
      return serie;
    })
  }
  
  // 设置图表选项
  dailyStatsChart.setOption(option)
}

// 初始化物品类型饼图
const initItemTypePie = () => {
  if (!itemTypePieRef.value) return
  
  // 销毁现有实例
  if (itemTypePie) {
    itemTypePie.dispose()
  }
  
  // 初始化图表
  itemTypePie = echarts.init(itemTypePieRef.value)
  
  // 交易物品分布数据
  const itemCategories = [
    { name: '宠物', value: 253, itemStyle: { color: '#4facfe' } },
    { name: '精灵球', value: 186, itemStyle: { color: '#43e97b' } },
    { name: '树果', value: 134, itemStyle: { color: '#fbd786' } },
    { name: '药剂', value: 95, itemStyle: { color: '#f78ca0' } },
    { name: '其他道具', value: 78, itemStyle: { color: '#a18cd1' } }
  ]
  
  // 配置图表选项
  const option = {
    backgroundColor: 'transparent',
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b}: {c} ({d}%)',
      backgroundColor: 'rgba(255, 255, 255, 0.9)',
      borderWidth: 1,
      borderColor: '#eeeeee',
      padding: [10, 12],
      textStyle: {
        color: '#333333',
        fontSize: 12
      }
    },
    legend: {
      orient: 'vertical',
      left: 'left',
      top: 'center',
      textStyle: {
        fontSize: 12,
        color: '#666'
      },
      icon: 'circle',
      itemWidth: 8,
      itemHeight: 8,
      itemGap: 10
    },
    series: [
      {
        name: '交易物品类型',
        type: 'pie',
        radius: ['45%', '70%'],
        center: ['50%', '50%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 4,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 14,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: itemCategories
      }
    ]
  }
  
  // 设置图表选项
  itemTypePie.setOption(option)
}

// 处理榜单类型切换
const handleRankTypeChange = (type) => {
  console.log('榜单类型切换:', type)
}

// 处理时间范围切换
const handleTradeRankTimeRangeChange = (range) => {
  console.log('榜单时间范围切换:', range)
}

// 修改API获取函数
const fetchDashboardData = async () => {
  try {
    const response = await axios.get('/api/dashboard/data', {
      params: {
        dateRange: dateRange.value,
        chartType: activeChartTab.value,
        itemTypeTimeRange: itemTypeTimeRange.value,
        rankType: rankType.value,
        tradeRankTimeRange: tradeRankTimeRange.value
      }
    })
    
    if (response.data.code === 200) {
      const data = response.data.data
      
      // 更新榜单数据
      if (rankType.value === 'user' && data.userTradeRank) {
        userTradeRankData.value = data.userTradeRank
      } else if (rankType.value === 'product' && data.productTradeRank) {
        productTradeRankData.value = data.productTradeRank
      }
      
      // 其他数据更新保持不变...
    }
  } catch (error) {
    console.error('获取仪表盘数据失败:', error)
  }
}

// 窗口大小变化时调整图表大小
const handleResize = () => {
  dailyStatsChart?.resize()
  itemTypePie?.resize()
}

// 销毁图表实例
const disposeCharts = () => {
  dailyStatsChart?.dispose()
  itemTypePie?.dispose()
  dailyStatsChart = null
  itemTypePie = null
}

// 组件挂载时初始化图表
onMounted(() => {
  window.addEventListener('resize', handleResize)
  nextTick(() => {
    initCharts()
    fetchDashboardData()
  })
})

// 组件卸载时移除事件监听和销毁图表
onUnmounted(() => {
  window.removeEventListener('resize', handleResize)
  disposeCharts()
})
</script>

<style lang="scss" scoped>
.dashboard-container {
  padding: 20px;
  background-color: #f7f8fa;
  min-height: calc(100vh - 84px);
}

.dashboard-header {
  margin-bottom: 20px;
  
  h1 {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0;
  }
}

.dashboard-stats {
  margin-bottom: 20px;
  
  .stat-card {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;
    height: 100%;
    
    &:hover {
      box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.08);
    }
    
    .stat-header {
      padding: 16px 20px 0;
      
      .stat-label {
        font-size: 14px;
        color: #909399;
      }
    }
    
    .stat-content {
      padding: 16px 20px 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      .stat-value-wrapper {
        flex: 1;
        
        .stat-value {
          font-size: 28px;
          font-weight: 600;
          color: #303133;
          margin-bottom: 8px;
        }
        
        .stat-trend {
          font-size: 12px;
          display: flex;
          align-items: center;
          
          &.up {
            color: #67C23A;
          }
          
          &.down {
            color: #F56C6C;
          }
          
          .el-icon {
            margin-right: 2px;
            font-size: 12px;
          }
        }
      }
      
      .stat-icon {
        width: 46px;
        height: 46px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
        
        .el-icon {
          font-size: 24px;
          color: white;
        }
        
        &.users-icon {
          background: linear-gradient(135deg, #4facfe, #00f2fe);
        }
        
        &.online-icon {
          background: linear-gradient(135deg, #43e97b, #38f9d7);
        }
        
        &.trade-icon {
          background: linear-gradient(135deg, #fa709a, #fee140);
        }
        
        &.money-icon {
          background: linear-gradient(135deg, #a18cd1, #fbc2eb);
        }
      }
    }
  }
}

.dashboard-charts {
  .chart-section {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    
    .chart-header {
      padding: 16px 20px;
      border-bottom: 1px solid #f0f0f0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-shrink: 0;
      
      .chart-title {
        h2 {
          font-size: 16px;
          font-weight: 600;
          color: #303133;
          margin: 0;
        }
      }
      
      .chart-actions {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
      }
    }
    
    .chart-container {
      padding: 15px;
      flex-grow: 1;
    }
  }
}

// 表格中的颜色
.text-green {
  color: #67C23A;
}

.text-red {
  color: #F56C6C;
}

// 媒体查询
@media (max-width: 1200px) {
  .dashboard-stats {
    .stat-card {
      .stat-content {
        .stat-value-wrapper {
          .stat-value {
            font-size: 24px;
          }
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .dashboard-container {
    padding: 16px;
  }
  
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    
    .chart-actions {
      margin-top: 12px;
    }
  }
}

/* 添加自定义tooltip样式 */
:deep(.el-tooltip__popper) {
  max-width: 200px;
  word-break: break-all;
  line-height: 1.4;
}

/* 调整图表标记点的样式 */
:deep(.echarts-tooltip-diy) {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #eee;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  padding: 6px 10px;
  border-radius: 4px;
}

/* 确保图表容器内的元素不超出 */
.chart-container {
  position: relative;
  overflow: hidden;
  
  /* 确保图表中的日期和数值标签分开显示 */
  :deep(.echarts-data-label) {
    position: relative !important;
    z-index: 1;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    padding: 2px 4px;
    font-size: 10px;
    white-space: nowrap;
  }
}

// 交易榜单相关样式
.rank-table-container {
  padding: 0 15px 15px;
  overflow-y: auto;
  flex-grow: 1;
  
  :deep(.el-table) {
    height: 100%;
    
    .el-table__body-wrapper {
      overflow-y: auto;
    }
    
    th {
      font-weight: 600;
      color: #606266;
      background: #f5f7fa;
      padding: 12px 0;
    }
    
    td {
      padding: 12px 0;
    }
    
    // 确保表格占满容器宽度
    table {
      width: 100% !important;
    }
  }
  
  .rank-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    font-weight: bold;
    background-color: #f5f5f5;
    margin: 0 auto;
    
    &.rank-1 {
      background-color: #f5bf42;
      color: white;
    }
    
    &.rank-2 {
      background-color: #c0c0c0;
      color: white;
    }
    
    &.rank-3 {
      background-color: #cd7f32;
      color: white;
    }
  }
  
  .user-cell, .product-cell {
    display: flex;
    align-items: center;
    padding: 0 10px;
    
    .user-avatar, .product-icon {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      margin-right: 12px;
      color: white;
      font-weight: bold;
    }
    
    .product-icon {
      border-radius: 8px;
      
      .el-icon {
        font-size: 18px;
      }
    }
    
    .user-name, .product-name {
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>